#!C:\Python\Python36\Python.exe
# -*- coding:utf-8 -*-
# @Time  : 2020-01-13 15:57
# @Author: iceman
# @File  : configHttp.py
import json

import requests
import readExcel


class RunMain():
    def send_get(self, url, data):
        result = requests.get(url=url, params=data)
        return result.text

    def send_post(self, url, data, headers):
        result = requests.post(url=url, data=data, headers=headers)
        return result.text

    def run_main(self, method, url=None, data=None, headers= None):
        result = None
        if method == 'post':
            result = self.send_post(url, data, headers)
        elif method == 'get':
            result = self.send_get(url, data)
        else:
            print('method错误')
        return result


if __name__ == '__main__':
    url1 = 'http://127.0.0.1:5000/login'
    data1 = readExcel.readExcel(2, 'C').get_xls()
    print("data1: " + str(data1))
    headers= {
        "Connection": "keep-alive",
        "Accept": "application/json",
        "Content-Type": "application/x-www-form-urlencoded",
        "Connection": "keep-alive",
        "Accept-Language": "zh-CN",
        "X-Requested-With": "XMLHttpRequest",
        "Referer": "a",
        "Content-Length": "18",
        "Host": "test-witwork.yiqijiao.net",
        "User-Agent": "Apache-HttpClient/4.5.6 (Java/1.8.0_131)",
    }
    result1 = RunMain().run_main('post', url1, {'user': 'admin', 'pwd': '123456'}, headers=None)
    result2 = RunMain().run_main('get', url1, 'user=xiaoming&pwd=111')
    result3 = RunMain().run_main('post',"http://test-witwork.yiqijiao.net/api/session/tests", "mobile=18215555153",headers=headers)
    # 将 str 对象转换为 Python 字典
    print(result1)
    print(result2)
    print(result3)
    if 'success' in result3:
        print("成功")
